﻿using System;
using fastCSharp.code.cSharp;

namespace diantou.web.exam
{
    /// <summary>
    /// 考试全局视图
    /// </summary>
    /// <typeparam name="viewType">视图类型</typeparam>
    abstract class view<viewType> : webView.view<viewType>
         where viewType : view<viewType>
    {
        /// <summary>
        /// 企业考试
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        protected diantou.examDataAccess.exam exam;
        /// <summary>
        /// 当前用户
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        protected diantou.examDataAccess.examUser examUser;
        /// <summary>
        /// 当前用户
        /// </summary>
        protected diantou.examDataAccess.examUser user
        {
            get
            {
                if (examUser == null)
                {
                    examUser = web.pub.GetExamUser(this);
                    if (examUser == null) examUser = diantou.examDataAccess.examUser.NullUser;
                }
                return examUser != diantou.examDataAccess.examUser.NullUser ? examUser : null;
            }
        }
        /// <summary>
        /// 用户考试
        /// </summary>
        protected userExam userExam
        {
            get { return new userExam { Exam = exam, User = user }; }
        }
        /// <summary>
        /// 加载视图
        /// </summary>
        /// <param name="searchEnginePath">搜索引擎重定向</param>
        /// <returns></returns>
        protected bool load(int examId, string searchEnginePath = null)
        {
            if (examId == 0)
            {
                checkSearchEngine(searchEnginePath, webConfig.NotFound404);
                return false;
            }
            exam = diantou.examDataAccess.clientCache.Exam[examId];
            if (exam != null && exam.Status != dataModel.exam.status.None) return true;
            AjaxResponse(webConfig.NotFound404);
            return false;
        }
    }
}
